package ru.samgtu.wst.plugin.sqlinj.swing;

import javax.swing.Action;
import javax.swing.JPanel;
import ru.samgtu.wst.model.ConversationID;
import ru.samgtu.wst.model.HttpUrl;
import ru.samgtu.wst.plugin.sqlinj.SqlInjection;
import ru.samgtu.wst.plugin.sqlinj.SqlInjectionModel;
import ru.samgtu.wst.ui.swing.SwingPluginUI;
import ru.samgtu.wst.util.swing.ColumnDataModel;

public class SqlInjectionPanel extends JPanel implements SwingPluginUI {
	private ColumnDataModel[] _vulnerableConversationColumns;

	private ColumnDataModel[] _vulnerableUrlColumns;

	SqlInjection _sqlinj = null;
	SqlInjectionModel _model = null;

	public SqlInjectionPanel(SqlInjection sqlinj) {
		_sqlinj = sqlinj;
		_model = sqlinj.getModel();
		// initComponents();

		_vulnerableConversationColumns = new ColumnDataModel[1];
		_vulnerableConversationColumns = new ColumnDataModel[] {
				 new ColumnDataModel() {
					@Override
					public String getColumnName() {
						return "SQL";
					}

					@Override
					public Object getValue(Object key) {
						return _model.isVulnerable((ConversationID) key) ? Boolean.TRUE
								: Boolean.FALSE;
					}

					@Override
					public Class getColumnClass() {
						return Boolean.class;
					}
				}, };

		_vulnerableUrlColumns = new ColumnDataModel[] { new ColumnDataModel() {
			
			public String getColumnName() {
				return "SQL";
			}

			@Override
			public Object getValue(Object key) {
				HttpUrl url = (HttpUrl) key;
				 return _model.isVulnerable(url) ? Boolean.TRUE
				 : Boolean.FALSE;
			}

			@Override
			public Class getColumnClass() {
				return Boolean.class;
			}
		}

		};

	}

	@Override
	public Action[] getConversationActions() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ColumnDataModel[] getConversationColumns() {
		// TODO Auto-generated method stub
		return _vulnerableConversationColumns;
	}

	@Override
	public JPanel getPanel() {
		return this;
	}

	@Override
	public Action[] getUrlActions() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ColumnDataModel[] getUrlColumns() {
		return _vulnerableUrlColumns;
	}

	@Override
	public String getPluginName() {
		return _sqlinj.getPluginName();
	}

}
